//
//  TMDWBMainViewController.swift
//  TMDWeiBo
//
//  Created by 汤明鼎 on 2017/1/16.
//  Copyright © 2017年 heimaitcast. All rights reserved.
//

import UIKit

class TMDWBMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = TMDWBTabBar()
        
        tabBar.closure = {
            print("中间按钮被点击")
        }
        
        setValue(tabBar, forKey:"tabBar")
        addChildViewController(childViewController: TMDWBHomeViewController(), title:"首页", imageName:"tabbar_home")
        addChildViewController(childViewController: TMDWBMessageViewController(), title:"消息", imageName:"tabbar_message_center")
        addChildViewController(childViewController: TMDWBDiscoverViewController(), title:"发现", imageName:"tabbar_discover")
        addChildViewController(childViewController: TMDWBProfileViewController(), title:"我", imageName:"tabbar_profile")
    }
    

}

//创建子控制器
extension TMDWBMainViewController{
    func addChildViewController(childViewController:UIViewController,title:String,imageName:String){
        
        childViewController.title = title
        childViewController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:TMDMainColor], for: UIControlState.selected)
        childViewController.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        childViewController.tabBarItem.selectedImage = UIImage(named:"\(imageName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        addChildViewController(TMDWBVNAVController(rootViewController: childViewController))
    }


}
